//
//  HomeViewController.m
//  lhpc_manager
//
//  Created by 李英杰 on 2017/9/5.
//  Copyright © 2017年 zhaoyongjie. All rights reserved.
//

#import "HomeViewController.h"
#import "UnCompleteViewController.h"
#import "CompleteViewController.h"
#import "HomeTopView.h"
#import "PersonalCenterController.h"
#import "WebViewController.h"
#import "VerifyPhoneController.h"

@interface HomeViewController ()<HomeTopViewDelegate>

@property (nonatomic, strong) HomeTopView *topView;

@property (nonatomic, strong) UIView *containView;

@property (nonatomic, strong) UnCompleteViewController *unComVC;

@property (nonatomic, strong) CompleteViewController *comVC;

@property (nonatomic, strong) UIButton *rightBtn;

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"来回推广";
    
    [self setNavi];
    
    [self setupChildController];
    
    [self setupChildViews];
    
}

- (void)setNavi {
    UIBarButtonItem *leftBI = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"home_me"] style:UIBarButtonItemStyleDone target:self action:@selector(personalCenter)];
    self.navigationItem.leftBarButtonItem = leftBI;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightBtn];
}

- (void)personalCenter {
    PersonalCenterController *vc = [[PersonalCenterController alloc] init];
//    VerifyPhoneController *vc = (VerifyPhoneController *)LHGetSB_VC(@"VerifyPhone");
    [self.navigationController pushViewController:vc animated:YES];
    
}

-(void)rightButtonAction{
    
    WebViewController *vc = [[WebViewController alloc] init];    
    vc.urlStr = LHSetH5RequestAPI(LHH5CashRules);
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)setupChildController {
    [self addChildViewController:self.unComVC];
    [self addChildViewController:self.comVC];
}

- (void)setupChildViews {
    [self.view addSubview:self.topView];
    [self.view addSubview:self.containView];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(44);
    }];
    
    [self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topView.mas_bottom);
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    self.unComVC.view.frame = self.containView.bounds;
    [self.containView addSubview:self.unComVC.view];
}


#pragma mark - TopDelegate

- (void)unChangeToMoneyAction:(UIButton *)sender {
    if (!self.unComVC.view.superview) {
        [self.comVC.view removeFromSuperview];
        self.unComVC.view.frame = self.containView.bounds;
        [self.containView addSubview:self.unComVC.view];
    }
    
}

- (void)hasChangedToMoneyAction:(UIButton *)sender {
    if (!self.comVC.view.superview) {
        [self.unComVC.view removeFromSuperview];
        self.comVC.view.frame = self.containView.bounds;
        [self.containView addSubview:self.comVC.view];
    }
}

#pragma mark - getter 

- (HomeTopView *)topView {
    if (!_topView) {
        _topView = [[HomeTopView alloc] init];
        _topView.delegate = self;
    }
    return _topView;
}

- (UIView *)containView {
    if (!_containView) {
        _containView = [[UIView alloc] init];
    }
    return _containView;
}

- (UnCompleteViewController *)unComVC {
    if (!_unComVC) {
        _unComVC = [[UnCompleteViewController alloc] init];
    }
    return _unComVC;
}

- (CompleteViewController *)comVC {
    if (!_comVC) {
        _comVC = [[CompleteViewController alloc] init];
    }
    return _comVC;
}

- (UIButton *)rightBtn {
    if (!_rightBtn) {
        _rightBtn = [[UIButton alloc] init];
        _rightBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [_rightBtn setTitleColor:ORANGCOLOR forState:UIControlStateNormal];
        [_rightBtn setTitle:@"推广规则" forState:UIControlStateNormal];
        [_rightBtn sizeToFit];
        [_rightBtn addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
        _rightBtn.selected = NO;
    }
    return _rightBtn;
}


@end
